/*
 ============================================================================
 Name		: GZIPParser.h
 Author	  : haoxu
 Version	 : 1.0
 Copyright   : Tencent Research
 Description : CGZIPParser declaration
 ============================================================================
 */

#ifndef GZIPPARSER_H
#define GZIPPARSER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <ezlib.h>
#include "OSDefine.h"
#include "QSString.h"

// CLASS DECLARATION

/**
 *  CCGZIPParser
 *  
 *  Class use to decompress DEFLATE format data.
 *  
 *  Note:
 *  
 *  Only naked DEFLATE format(rfc 1951) is supported,
 *  not gzip(rfc 1952), not zlib(rfc 1950) data format.
 *  
 *  Typical Usage:
 *	
 *	CQSString data;
 *	pParser->BeginL();
 *	
 *	// Continually get input data
 *	while((in_len = somewhere.GetInput(inbuf, inbuf_size)) > 0)
 *	{
 *	    // provide input data
 *	    pParser->SetInput(inbuf, in_len);
 *	
 *	    // obtain output data
 *	    while ((out_len = pParser->DecompressL(outbuf, outbuf_size)) > 0) {
 *		    data.AppendData(outbuf, out_len);
 *	    }
 *	}
 *	
 *	pParser->EndL();
 */
class CGZIPParser: public CBase
{
public:
	// Constructors and destructor

	/**
	 * Constructor.
	 */
	EXPORT_C CGZIPParser();
	
	/**
	 * Destructor.
	 */
	EXPORT_C ~CGZIPParser();

public:
	/**
	 * Init inner zlib stream,
	 * invoke this method when start decompress a stream.
	 */
	EXPORT_C void BeginL();
	
	/**
	 * provide compressed input data.
	 * 
	 * @param aSrcBuf input buf
	 * @param alength input buf length
	 */
	EXPORT_C void SetInput(QPBYTE aSrcBuf, QINT aLength);
	
	/*
	 * Return uncompressed data that extract from input,
	 * this method use a inner buffer to cache output.
	 */
	EXPORT_C CQSString DecompressL();
	
	/**
	 * return uncompressed data that extract from input.
	 *
	 * @param aDstBuf output buf
	 * @param aLength output buf length
	 */
	EXPORT_C QINT DecompressL(QPBYTE aDstBuf, QINT aLength);
	
	/**
	 * End inner zlib stream,
	 * free all resources it used to decompress data,
	 * Invoke this method when done decompress a stream.
	 */
	EXPORT_C void EndL();
	
private:
	z_stream m_zStream;
};

#endif // GZIPPARSER_H
